#include <cstdio>
#include <iostream>
#include<unistd.h>
#include<string.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<stdlib.h>



using namespace std;

int main()
{
    pid_t id = id = fork();
    if(id == 0)
    {
        int cnt = 10;
        while(cnt--)
        {
            sleep(1);
            printf("i am child process pid:%d\n",getpid());
        }
        exit(0);
    }
    else if(id > 0 )
    {
        int status;

        pid_t rid = waitpid(-1,&status,0);
        if(rid > 0)
        { 
            sleep(2);
            printf("退出信号:%d,退出码:%d,coredump:%d\n",WIFEXITED(status),WEXITSTATUS(status),status>>7&1);  
            while(true)
            {
                sleep(1);
                printf("parent pid:%d\n",getpid());
            }

        }   
    }
    else
    {
        printf("errno : %d, errstring: %s\n", errno, strerror(errno));
        return errno;
    }

    return 0;
}
